package j2metris;

/**
 * Represents the six directions that a <code>Piece</code> can be moved in: up,
 * right, down, left, clockwise, and counterclockwise. The directions are
 * represented respectively as static variables of the Direction class.
 */
public class Direction
{
    public static final class TranslationDirection extends Direction
    {
        private final Coordinate coord;
        private TranslationDirection(String repr, Coordinate c)
        {
            super(repr);
            coord = c;
        }
        /**
         * Returns a <code>Coordinate</code> that, if added to another coordinate,
         * would move it in the direction represented by this object.
         */
        public Coordinate getCoordinate()
        {
            return coord;
        }
    }
    public static final class RotationDirection extends Direction
    {
        private final int intRepresentation;
        private RotationDirection(String repr, int direction)
        {
            super(repr);
            intRepresentation = direction;
        }
        /**
         * Returns an int that, applied to various functions, will cause rotation
         * in the direction represented by this object -- 1 for clockwise, -1
         * for counterclockwise.
         */
        public int getInt()
        {
            return intRepresentation;
        }
    }
    private final String name;
    public String toString()
    {
        return name;
    }
    private Direction(String repr)
    {
        name = repr;
    }
    public boolean isARotationDirection()
    {
        return this == CLOCKWISE || this == COUNTERCLOCKWISE;
    }

    public static TranslationDirection UP = new TranslationDirection(
            "UP", new Coordinate(0, -1));
    public static TranslationDirection RIGHT = new TranslationDirection(
            "RIGHT", new Coordinate(1, 0));
    public static TranslationDirection DOWN = new TranslationDirection(
            "DOWN", new Coordinate(0, 1));
    public static TranslationDirection LEFT = new TranslationDirection(
            "LEFT", new Coordinate(-1, 0));
    public static RotationDirection CLOCKWISE = new RotationDirection(
            "CLOCKWISE", 1);
    public static RotationDirection COUNTERCLOCKWISE = new RotationDirection(
            "COUNTERCLOCKWISE", -1);
}


